/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package presentation.guiForFundamentalFilter;

import business.fundamentalModel.*;
import dataAccess.databaseManagement.entity.ExchangeEntity;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.TreeMap;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JSpinner;
import presentation.mainJFrame;

/**
 *
 * @author TDINH
 */
public class FilterJPanel extends javax.swing.JPanel {

    /**
     * Creates new form FilterJPanel
     */
    public FilterJPanel() {
        initComponents();
        initOtherComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        dateJPanel = new javax.swing.JPanel();
        fromDateJLabel = new javax.swing.JLabel();
        toDateJLabel = new javax.swing.JLabel();
        fromDatejSpinner = new javax.swing.JSpinner();
        toDatejSpinner = new javax.swing.JSpinner();
        fundamentalModelJPanel = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        filterJTable = new javax.swing.JTable();
        modelJLabel = new javax.swing.JLabel();
        modelJComboBox = new javax.swing.JComboBox();
        criteriaJPanel = new javax.swing.JPanel();
        containerJPanel = new javax.swing.JPanel();
        exchangeJLabel = new javax.swing.JLabel();
        exchangeJComboBox = new javax.swing.JComboBox();
        filterJButton = new javax.swing.JButton();
        sectorRankingJPanel = new javax.swing.JPanel();
        sectorJLabel = new javax.swing.JLabel();
        sectorJComboBox = new javax.swing.JComboBox();
        jScrollPane2 = new javax.swing.JScrollPane();
        sectorRankingJTable = new javax.swing.JTable();
        rankJButton = new javax.swing.JButton();

        dateJPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "DATE", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        fromDateJLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        fromDateJLabel.setText("Begin:");

        toDateJLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        toDateJLabel.setText("End:");

        fromDatejSpinner.setModel(new javax.swing.SpinnerDateModel());
        fromDatejSpinner.setEditor(new JSpinner.DateEditor(fromDatejSpinner, "MM/dd/yyyy"));
        fromDatejSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                fromDatejSpinnerStateChanged(evt);
            }
        });

        toDatejSpinner.setModel(new javax.swing.SpinnerDateModel());
        toDatejSpinner.setEditor(new JSpinner.DateEditor(toDatejSpinner, "MM/dd/yyyy"));
        toDatejSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                toDatejSpinnerStateChanged(evt);
            }
        });

        javax.swing.GroupLayout dateJPanelLayout = new javax.swing.GroupLayout(dateJPanel);
        dateJPanel.setLayout(dateJPanelLayout);
        dateJPanelLayout.setHorizontalGroup(
            dateJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(dateJPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(fromDateJLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(fromDatejSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(toDateJLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(toDatejSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        dateJPanelLayout.setVerticalGroup(
            dateJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, dateJPanelLayout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addGroup(dateJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(dateJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(fromDateJLabel)
                        .addComponent(fromDatejSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(toDateJLabel))
                    .addComponent(toDatejSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        fundamentalModelJPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "FUNDAMENTAL MODEL", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        filterJTable.setModel(new FilterTableModel());
        jScrollPane1.setViewportView(filterJTable);

        modelJLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        modelJLabel.setText("Model:");

        modelJComboBox.setEditable(true);
        modelJComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                modelJComboBoxActionPerformed(evt);
            }
        });

        criteriaJPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Criteria", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        containerJPanel.setLayout(new java.awt.GridLayout(1, 0));

        javax.swing.GroupLayout criteriaJPanelLayout = new javax.swing.GroupLayout(criteriaJPanel);
        criteriaJPanel.setLayout(criteriaJPanelLayout);
        criteriaJPanelLayout.setHorizontalGroup(
            criteriaJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(containerJPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        criteriaJPanelLayout.setVerticalGroup(
            criteriaJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(containerJPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        exchangeJLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        exchangeJLabel.setText("Exchange:");

        exchangeJComboBox.setEditable(true);
        exchangeJComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exchangeJComboBoxActionPerformed(evt);
            }
        });

        filterJButton.setText("Filter");
        filterJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                filterJButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout fundamentalModelJPanelLayout = new javax.swing.GroupLayout(fundamentalModelJPanel);
        fundamentalModelJPanel.setLayout(fundamentalModelJPanelLayout);
        fundamentalModelJPanelLayout.setHorizontalGroup(
            fundamentalModelJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(fundamentalModelJPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(fundamentalModelJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(criteriaJPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(fundamentalModelJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(fundamentalModelJPanelLayout.createSequentialGroup()
                            .addComponent(modelJLabel)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(modelJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, fundamentalModelJPanelLayout.createSequentialGroup()
                            .addComponent(exchangeJLabel)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(exchangeJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(fundamentalModelJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 677, Short.MAX_VALUE)
                    .addGroup(fundamentalModelJPanelLayout.createSequentialGroup()
                        .addComponent(filterJButton)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        fundamentalModelJPanelLayout.setVerticalGroup(
            fundamentalModelJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(fundamentalModelJPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(fundamentalModelJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(exchangeJLabel)
                    .addComponent(exchangeJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(filterJButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(fundamentalModelJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(fundamentalModelJPanelLayout.createSequentialGroup()
                        .addGroup(fundamentalModelJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(modelJLabel)
                            .addComponent(modelJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(criteriaJPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 217, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        sectorRankingJPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "SECTOR RANKING", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        sectorJLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        sectorJLabel.setText("Sector:");

        sectorJComboBox.setEditable(true);
        sectorJComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sectorJComboBoxActionPerformed(evt);
            }
        });

        sectorRankingJTable.setModel(new RankingTableModel());
        jScrollPane2.setViewportView(sectorRankingJTable);

        rankJButton.setText("Rank");
        rankJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rankJButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout sectorRankingJPanelLayout = new javax.swing.GroupLayout(sectorRankingJPanel);
        sectorRankingJPanel.setLayout(sectorRankingJPanelLayout);
        sectorRankingJPanelLayout.setHorizontalGroup(
            sectorRankingJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(sectorRankingJPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(sectorRankingJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(sectorRankingJPanelLayout.createSequentialGroup()
                        .addComponent(sectorJLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(sectorJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(rankJButton))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane2)
                .addContainerGap())
        );
        sectorRankingJPanelLayout.setVerticalGroup(
            sectorRankingJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(sectorRankingJPanelLayout.createSequentialGroup()
                .addGroup(sectorRankingJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addGroup(sectorRankingJPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(sectorRankingJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(sectorJLabel)
                            .addComponent(sectorJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(rankJButton)
                        .addGap(0, 91, Short.MAX_VALUE)))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(sectorRankingJPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(fundamentalModelJPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(dateJPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(dateJPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(fundamentalModelJPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(sectorRankingJPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void fromDatejSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_fromDatejSpinnerStateChanged
        fromDate = (Date) fromDatejSpinner.getValue();
    }//GEN-LAST:event_fromDatejSpinnerStateChanged

    private void toDatejSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_toDatejSpinnerStateChanged
        toDate = (Date) toDatejSpinner.getValue();
    }//GEN-LAST:event_toDatejSpinnerStateChanged

    private void exchangeJComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exchangeJComboBoxActionPerformed
    }//GEN-LAST:event_exchangeJComboBoxActionPerformed

    private void sectorJComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sectorJComboBoxActionPerformed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_sectorJComboBoxActionPerformed

    private void modelJComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_modelJComboBoxActionPerformed
        // TODO add your handling code here:
        containerJPanel.removeAll();
        if (modelJComboBox.getSelectedIndex() == -1) {
            return;
        }
        
        if (((String) modelJComboBox.getSelectedItem()).equals(FundamentalModelAPI.PFG)) {
            modelCriteriaJPanel = new PFGModelJPanel();
        } else if (((String) modelJComboBox.getSelectedItem()).equals(FundamentalModelAPI.PhT)){
            modelCriteriaJPanel = new PhiltownModelJPanel();
        } else if (((String) modelJComboBox.getSelectedItem()).equals(FundamentalModelAPI.Custom)){
            modelCriteriaJPanel = new CustomJPanel();
        }
        
        containerJPanel.add(modelCriteriaJPanel);
	containerJPanel.updateUI();
    }//GEN-LAST:event_modelJComboBoxActionPerformed

    private void filterJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_filterJButtonActionPerformed
	String modelName = ((String) modelJComboBox.getSelectedItem());
        
        AbstractFundamentalModel abstractFModel = FundamentalModelAPI.getFundamentalModel(modelName);
        TreeMap<String, Object> valueMap = new TreeMap<String, Object>();
        
        ExchangeEntity exchangeEntity = (ExchangeEntity) exchangeJComboBox.getSelectedItem();
                
        valueMap.put("Asset List", AbstractFundamentalModel.assList(exchangeEntity));
        valueMap.put("Date", fromDate);
        
        if (modelName.equals(FundamentalModelAPI.PFG)) {
            valueMap.put("P/E", 5.0);
            valueMap.put("P/B", 1.0);
            valueMap.put("ROE", 0.27);
            valueMap.put("RevenueGrowth", 0.3);            
            FilterTableModel.types = new Class[]{ 
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            FilterTableModel.canEdit = new boolean[]{
                false, false, false, false, false, false
            };
            FilterTableModel.columnNames = new String[]{
                "Symbol", "LatestPrice", "P/E", "P/B", "ROE", "RevenueGrowth"
            };
        } else if (modelName.equals(FundamentalModelAPI.PhT)) {
            valueMap.put("ROE", 0.27);
            FilterTableModel.types = new Class[]{ 
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            FilterTableModel.canEdit = new boolean[]{
                false, false, false, false, false, false
            };
            FilterTableModel.columnNames = new String[]{
                "Symbol", "LatestPrice", "P/E", "P/B", "ROE", "RevenueGrowth"
            };

        } else {
            CustomTableModel customTable = ((CustomJPanel) modelCriteriaJPanel).getCustomTable();
            FilterTableModel.canEdit = new boolean[customTable.getRowCount()+2];
            FilterTableModel.columnNames = new String[customTable.getRowCount()+2];
            FilterTableModel.types = new Class[customTable.getRowCount()+2];
            FilterTableModel.canEdit[0] = false;
            FilterTableModel.canEdit[1] = false;
            FilterTableModel.columnNames[0] = "Symbol";
            FilterTableModel.columnNames[1] = "LatestPrice";
            FilterTableModel.types[0] = java.lang.String.class;
            FilterTableModel.types[1] = java.lang.String.class;
            for (int i = 0; i < customTable.getRowCount(); ++i) {
                FilterTableModel.types[i+2] = java.lang.String.class;
                FilterTableModel.canEdit[i+2] = false;
                FilterTableModel.columnNames[i+2] = (String)customTable.getValueAt(i, 0);
                System.out.println((String)customTable.getValueAt(i, 0) + "Min" + (Double)customTable.getValueAt(i, 1));
                System.out.println((String)customTable.getValueAt(i, 0) + "Max" + (Double)customTable.getValueAt(i, 2));
                valueMap.put((String)customTable.getValueAt(i, 0) + "Min", (Double)customTable.getValueAt(i, 1));
                valueMap.put((String)customTable.getValueAt(i, 0) + "Max", (Double)customTable.getValueAt(i, 2));
            }
        }
        filterJTable.setModel(new FilterTableModel());
        filterJTable.updateUI();
              
        abstractFModel.setParameterValue(valueMap);
        System.out.println(abstractFModel.toString());
        
        FilterTableModel filterTableModel = (FilterTableModel) filterJTable.getModel();
        filterTableModel.setData(abstractFModel.getAssetStatList());
        filterJTable.updateUI();
        
        FundamentalEvaluation.toFile(modelName, abstractFModel.getAssetStatList(), exchangeEntity.getName(), fromDate, toDate);
    }//GEN-LAST:event_filterJButtonActionPerformed

    private void rankJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rankJButtonActionPerformed
        String sector = (String) sectorJComboBox.getSelectedItem(); // get sectorname from textbo
        SectorRanking sectorR = new SectorRanking(sector, fromDate);
        ArrayList<AssetStat> secRankList = sectorR.getAsStatList();
        while (secRankList.size() > 3) {
            secRankList.remove(secRankList.size()-1);
        }
        
        RankingTableModel sectorRankingTableModel = (RankingTableModel) sectorRankingJTable.getModel();
        sectorRankingTableModel.setData(secRankList);
        sectorRankingJTable.updateUI();    
        
        SectorRanking.toFile(sector, secRankList, "INDEX", fromDate, toDate);
    }//GEN-LAST:event_rankJButtonActionPerformed

    //Variables 
    private Date fromDate;
    private Date toDate;
    private javax.swing.JPanel modelCriteriaJPanel;
    
//    private ComboKeyHandler exchangeComboKeyHandler;
//    private ComboKeyHandler modelComboKeyHandler;
    
    private void initOtherComponents() {
        Calendar now = Calendar.getInstance();
        toDatejSpinner.setValue(now.getTime());
        now.set(2011, 2, 31);
        fromDatejSpinner.setValue(now.getTime());

        exchangeJComboBox.setModel(new DefaultComboBoxModel(mainJFrame.mappingExchangeID_Assets.keySet().toArray()));
//        exchangeComboKeyHandler = new ComboKeyHandler(exchangeJComboBox);
//        JTextField fieldExchange = (JTextField) exchangeJComboBox.getEditor().getEditorComponent();
//        fieldExchange.addKeyListener(exchangeComboKeyHandler);
        
        modelJComboBox.setModel(new DefaultComboBoxModel(FundamentalModelAPI.FUNDAMENTAL_MODEL_LIST));
//        exchangeComboKeyHandler = new ComboKeyHandler(exchangeJComboBox);
//        JTextField fieldExchange = (JTextField) exchangeJComboBox.getEditor().getEditorComponent();
//        fieldExchange.addKeyListener(exchangeComboKeyHandler);        
        
        sectorJComboBox.setModel(new DefaultComboBoxModel(SectorRanking.SECTOR_LIST));
//        assetJComboBox.setModel(new DefaultComboBoxModel(mainJFrame.mappingExchangeID_Assets.get((ExchangeEntity) exchangeJComboBox.getSelectedItem())));
//        assetComboKeyHandler = new ComboKeyHandler(assetJComboBox);
//        JTextField fieldSymbol = (JTextField) assetJComboBox.getEditor().getEditorComponent();
//        fieldSymbol.addKeyListener(assetComboKeyHandler);
//
//        asset = (AssetEntity) assetJComboBox.getSelectedItem();

        toDate = (Date) toDatejSpinner.getValue();
        fromDate = (Date) fromDatejSpinner.getValue();

        if (((String) modelJComboBox.getSelectedItem()).equals(FundamentalModelAPI.PFG)) {
            modelCriteriaJPanel = new PFGModelJPanel();
        } else {
            modelCriteriaJPanel = new PhiltownModelJPanel();
        }
        
        containerJPanel.add(modelCriteriaJPanel);
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel containerJPanel;
    private javax.swing.JPanel criteriaJPanel;
    private javax.swing.JPanel dateJPanel;
    private javax.swing.JComboBox exchangeJComboBox;
    private javax.swing.JLabel exchangeJLabel;
    private javax.swing.JButton filterJButton;
    private javax.swing.JTable filterJTable;
    private javax.swing.JLabel fromDateJLabel;
    private javax.swing.JSpinner fromDatejSpinner;
    private javax.swing.JPanel fundamentalModelJPanel;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JComboBox modelJComboBox;
    private javax.swing.JLabel modelJLabel;
    private javax.swing.JButton rankJButton;
    private javax.swing.JComboBox sectorJComboBox;
    private javax.swing.JLabel sectorJLabel;
    private javax.swing.JPanel sectorRankingJPanel;
    private javax.swing.JTable sectorRankingJTable;
    private javax.swing.JLabel toDateJLabel;
    private javax.swing.JSpinner toDatejSpinner;
    // End of variables declaration//GEN-END:variables
}
